package com.hippo.client.controller.sys;

import com.hippo.client.pojo.Person;
import com.hippo.core.pojo.vo.result.BaseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

/**
 * @ClassName PageController
 * @Description TODO 页面渲染-前后不分离
 * @Author tangxl
 * @create 2023-06-16 11:42
 **/
@Tag(name = "页面渲染-前后不分离")
@Controller //适配 服务端渲染 前后不分离模式开始
public class PageController {
    @Autowired
    private MessageSource messageSource;

    @GetMapping("/index")
    @Operation(summary = "单文件上传(拦截)")
    public String index(String name, Model model){
        model.addAttribute("name",name);
        //模板的逻辑视图名称
        return "index";
    }

    @GetMapping("/list")
    @Operation(summary = "列表页")
    public String list(Model model){
        List<Person> list = Arrays.asList(
                new Person(1L, "张三1", "", 15,"pm"),
                new Person(3L, "张三2", "zs2@qq.com", 16,"pm"),
                new Person(4L, "张三333", "zs3@qq.com", 17,"pm"),
                new Person(7L, "张三444", "zs4@qq.com", 18,"admin"),
                new Person(8L, "张三5", "zs5@qq.com", 19,"hr")
        );

        model.addAttribute("persons",list);

        return "list";
    }

    @Operation(summary = "国际化消息测试")
    @GetMapping("/message")
    public BaseResult message(HttpServletRequest request){
        // 获取国际化区域
        Locale locale = request.getLocale();
        return BaseResult.ok(messageSource.getMessage("login", null, locale));
    }


}
